﻿Imports System.Linq
Imports System
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.Collections.Specialized
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Windows.Data
Imports System.Windows.Interop

Namespace ViewModels

    Public Class ViewModelMainWindow

#Region "Variables privées"
        Private _model As Model
        Private _Workspaces As ReadOnlyObservableCollection(Of ViewModelCommand)
        Private _NavigCommands As ReadOnlyObservableCollection(Of ViewModelCommand)
        Private _TxGarEncoursCommands As ReadOnlyObservableCollection(Of ViewModelCommand)
        Private _TxGarReferentielCommands As ReadOnlyObservableCollection(Of ViewModelCommand)
        Private _TxGarGranulariteCommands As ReadOnlyObservableCollection(Of ViewModelCommand)
        Private _TxGarTechniquesCommands As ReadOnlyObservableCollection(Of ViewModelCommand)
        Private _TxGarResEqTarifCommands As ReadOnlyObservableCollection(Of ViewModelCommand)
        Private _TxGarResProjCommands As ReadOnlyObservableCollection(Of ViewModelCommand)
        Private _ExitCommand As ICommand
        Private _MaximizeCommand As ICommand
        Private _ReduceCommand As ICommand
#End Region

#Region "Constructeur"

        Public Sub New(ByVal Model As Model)
            _model = Model
            createCommands()
        End Sub
#End Region

#Region "Propriétés"
        Private _ViewModelCmdEncoursImport As ViewModelCmdEncoursImport
        Public ReadOnly Property ViewModelCmdEncoursImport() As ViewModelCmdEncoursImport
            Get
                If _ViewModelCmdEncoursImport Is Nothing Then
                    createCommands()
                End If
                Return _ViewModelCmdEncoursImport
            End Get
        End Property
        Private _ViewModelCmdEncoursCorresp As ViewModelCmdEncoursCorresp
        Public ReadOnly Property ViewModelCmdEncoursCorresp() As ViewModelCmdEncoursCorresp
            Get
                If _ViewModelCmdEncoursCorresp Is Nothing Then
                    createCommands()
                End If
                Return _ViewModelCmdEncoursCorresp
            End Get
        End Property
#End Region

#Region "Les commandes"

        ''' <summary>
        ''' Retourne une liste en lecture seule des vues à afficher dans l'espace de travail
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property Workspaces As ReadOnlyObservableCollection(Of ViewModelCommand)
            Get
                If _Workspaces Is Nothing Then
                    Me.createCommands()
                    _Workspaces = _TxGarEncoursCommands
                End If
                Return _Workspaces
            End Get
        End Property

        ''' <summary>
        ''' Retourne une liste en lecture seule des commandes 
        ''' à afficher dans l'arborescence et que l'utilisateur peut exécuter
        ''' </summary>
        Public ReadOnly Property CommandsNavig() As ReadOnlyObservableCollection(Of ViewModelCommand)
            Get
                If _NavigCommands Is Nothing Then
                    Me.createCommands()
                End If
                Return _NavigCommands
            End Get
        End Property

        Public ReadOnly Property ExitCommand() As ICommand
            Get
                If _ExitCommand Is Nothing Then
                    _ExitCommand = New DelegateCommand(Of Object)(AddressOf ExitCmd)
                End If
                Return _ExitCommand
            End Get
        End Property
        Public ReadOnly Property ReduceCommand() As ICommand
            Get
                If _ReduceCommand Is Nothing Then
                    _ReduceCommand = New DelegateCommand(Of Object)(AddressOf ReduceCmd)
                End If
                Return _ReduceCommand
            End Get
        End Property
        Public ReadOnly Property MaximizeCommand() As ICommand
            Get
                If _MaximizeCommand Is Nothing Then
                    _MaximizeCommand = New DelegateCommand(Of Object)(AddressOf MaximizeCmd)
                End If
                Return _MaximizeCommand
            End Get
        End Property

        Private Sub createCommands()

            Dim cmdsViewModel As New ObservableCollection(Of ViewModelCommand)
            Dim cmdNavigationOMANE As New DelegateCommand(Of String)(AddressOf cmdNavigOMANE)

            Dim ViewModeleCmdTxGarEncoursListCmd As New ObservableCollection(Of ViewModelCommand)
            _ViewModelCmdEncoursImport = New ViewModelCmdEncoursImport(_model, "Fichier Encours", cmdNavigationOMANE)
            _ViewModelCmdEncoursCorresp = New ViewModelCmdEncoursCorresp(_model, "Correspondances", cmdNavigationOMANE)
            ViewModeleCmdTxGarEncoursListCmd.Add(_ViewModelCmdEncoursImport)
            ViewModeleCmdTxGarEncoursListCmd.Add(_ViewModelCmdEncoursCorresp)
            ViewModeleCmdTxGarEncoursListCmd.Add(New ViewModelCmdEncoursRetrait(_model, "Retraitements", cmdNavigationOMANE))
            ViewModeleCmdTxGarEncoursListCmd.Add(New ViewModelCommand("Statistiques", cmdNavigationOMANE))

            Dim ViewModeleCmdTxGarReferentielListCmd As New ObservableCollection(Of ViewModelCommand)
            ViewModeleCmdTxGarReferentielListCmd.Add(New ViewModelCommand("Consultation", cmdNavigationOMANE))
            ViewModeleCmdTxGarReferentielListCmd.Add(New ViewModelCommand("Alimentation", cmdNavigationOMANE))

            Dim ViewModeleCmdTxGarGranulariteListCmd As New ObservableCollection(Of ViewModelCommand)
            ViewModeleCmdTxGarGranulariteListCmd.Add(New ViewModelCommand("Segmentation", cmdNavigationOMANE))

            Dim ViewModeleCmdTxGarTechniqueListCmd As New ObservableCollection(Of ViewModelCommand)
            ViewModeleCmdTxGarTechniqueListCmd.Add(New ViewModelCommand("Méthode de calcul", cmdNavigationOMANE))
            ViewModeleCmdTxGarTechniqueListCmd.Add(New ViewModelCommand("Données économiques", cmdNavigationOMANE))
            ViewModeleCmdTxGarTechniqueListCmd.Add(New ViewModelCommand("Garantie DC / PTIA", cmdNavigationOMANE))
            ViewModeleCmdTxGarTechniqueListCmd.Add(New ViewModelCommand("Garantie Incapacité / Invalidité", cmdNavigationOMANE))
            ViewModeleCmdTxGarTechniqueListCmd.Add(New ViewModelCommand("Estimateurs", cmdNavigationOMANE))

            Dim ViewModeleCmdTxGarResEqTarifListCmd As New ObservableCollection(Of ViewModelCommand)
            ViewModeleCmdTxGarResEqTarifListCmd.Add(New ViewModelCommand("Scénario central", cmdNavigationOMANE))

            Dim ViewModeleCmdTxGarResScenCentProjListCmd As New ObservableCollection(Of ViewModelCommand)
            ViewModeleCmdTxGarResScenCentProjListCmd.Add(New ViewModelCommand("Paramétrage", cmdNavigationOMANE))

            Dim ViewModeleCmdTarifListCmd As New ObservableCollection(Of ViewModelCommand)
            ViewModeleCmdTarifListCmd.Add(New ViewModelCommand("Echéancier", cmdNavigationOMANE))

            Dim ViewModeleCmdTxGarEncours As New ViewModelCommandGroup("Encours", cmdNavigationOMANE, ViewModeleCmdTxGarEncoursListCmd)
            Dim ViewModeleCmdTxGarReferentiel As New ViewModelCommandGroup("Référentielles", cmdNavigationOMANE, ViewModeleCmdTxGarReferentielListCmd)
            Dim ViewModeleCmdTxGarGranularite As New ViewModelCommandGroup("Granularité", cmdNavigationOMANE, ViewModeleCmdTxGarGranulariteListCmd)
            Dim ViewModeleCmdTxGarTechnique As New ViewModelCommandGroup("Techniques", cmdNavigationOMANE, ViewModeleCmdTxGarTechniqueListCmd)
            Dim ViewModeleCmdTxGarResEqTarif As New ViewModelCommandGroup("Equilibre tarifaire", cmdNavigationOMANE, ViewModeleCmdTxGarResEqTarifListCmd)
            Dim ViewModeleCmdTxGarResScenCentProj As New ViewModelCommandGroup("Scénario central", cmdNavigationOMANE, ViewModeleCmdTxGarResScenCentProjListCmd)
            Dim ViewModeleCmdTarif As New ViewModelCommandGroup("Tarification", cmdNavigationOMANE, ViewModeleCmdTarifListCmd)

            cmdsViewModel.Add(ViewModeleCmdTxGarEncours)
            cmdsViewModel.Add(ViewModeleCmdTxGarReferentiel)
            cmdsViewModel.Add(ViewModeleCmdTxGarGranularite)
            cmdsViewModel.Add(ViewModeleCmdTxGarTechnique)
            cmdsViewModel.Add(ViewModeleCmdTxGarResEqTarif)
            cmdsViewModel.Add(ViewModeleCmdTxGarResScenCentProj)
            cmdsViewModel.Add(ViewModeleCmdTarif)

            ''Dim ViewModeleCmdTarif As New ViewModelCommand("Tarification", cmdOMANE)
            ''Dim ViewModeleCmdTauxGaranti As New ViewModelCommand("Taux Garantis", cmdOMANE)
            ''Dim ViewModeleCmdOMANE As New ViewModelCommand("OMANE", cmdTauxGaranti)

            _NavigCommands = New ReadOnlyObservableCollection(Of ViewModelCommand)(cmdsViewModel)
            _TxGarEncoursCommands = New ReadOnlyObservableCollection(Of ViewModelCommand)(ViewModeleCmdTxGarEncoursListCmd)
            _TxGarReferentielCommands = New ReadOnlyObservableCollection(Of ViewModelCommand)(ViewModeleCmdTxGarReferentielListCmd)
            _TxGarGranulariteCommands = New ReadOnlyObservableCollection(Of ViewModelCommand)(ViewModeleCmdTxGarGranulariteListCmd)
            _TxGarTechniquesCommands = New ReadOnlyObservableCollection(Of ViewModelCommand)(ViewModeleCmdTxGarTechniqueListCmd)
            _TxGarResEqTarifCommands = New ReadOnlyObservableCollection(Of ViewModelCommand)(ViewModeleCmdTxGarResEqTarifListCmd)
            _TxGarResProjCommands = New ReadOnlyObservableCollection(Of ViewModelCommand)(ViewModeleCmdTxGarResScenCentProjListCmd)

        End Sub
        Private Sub cmdNavigOMANE(ByVal Lien As String)
            'Ajouter un paramètre permettant de connaitre la vue demandée
            MsgBox("Vous avez cliqué sur l'élément " & Lien & " de l'arborescence")
        End Sub
        Private Sub cmdNavigTauxGaranti()
            MsgBox("Vous avez cliqué sur l'item TauxGaranti")
        End Sub

        Private Sub ExitCmd()
            Application.Current.MainWindow.Close()
        End Sub
        Private Sub MaximizeCmd()
            Dim win As Window = Application.Current.MainWindow
            Select Case win.WindowState
                Case WindowState.Maximized
                    win.WindowState = WindowState.Normal
                    Exit Select
                Case WindowState.Normal
                    win.WindowState = WindowState.Maximized
                    Exit Select
            End Select
        End Sub
        Private Sub ReduceCmd()
            Dim win As Window = Application.Current.MainWindow
            Select Case win.Visibility
                Case Visibility.Hidden
                    win.Visibility = Visibility.Visible
                    Exit Select
                Case Visibility.Visible
                    win.ShowInTaskbar = True
                    Exit Select
            End Select
        End Sub

#End Region

    End Class

End Namespace